package org.example.route.mapper;

import org.apache.ibatis.annotations.*;
import org.example.route.model.pojo.Order;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {


    @Insert("insert into `order` (user_id,price_id,seat_id,status,carriage_id,create_time) values(#{userId},#{priceId},#{seatId},#{status},#{carriageId},#{createTime})")
    void add(Order order);

    @Select("select * from `order` where id = #{orderId}")
    Order getById(Long orderId);

    @Select("select * from `order` where user_id = #{id}")
    List<Order> listById(Long id);

    @Select("select * from `order` where user_id = #{id}")
    List<Order> listByUserId(Long id);

    void update(Order order);

    @Select("select * from `order` where status = #{waitPay} and `order`.create_time < #{localDateTime}")
    List<Order> getByStatusAndOrderTimeLT(Long waitPay, LocalDateTime localDateTime);

    @Delete("delete from `order` where id = #{orderId}")
    void deleteById(Long orderId);

    @Select("select * from `order` where status = #{cancel}")
    List<Order> getByStatus(Long cancel);

    @Update("update `order` set status = 2 where id = #{orderId} ;")
    void cancelById(Long orderId);

   // void updateBatch(List<Order> orders);

    /**
     *
     * 查询已经过站的订单
     *
     * **/
    List<Order> getByStatusAndEndTimeLT(
            @Param("payed")Long payed,
            @Param("now")LocalDateTime now);



    /**
     *
     * 根据购买的起始时间查询订单
     *
     * **/
    List<Order> getByStartAndEndTime(@Param("startTime") LocalDateTime startTime,
                                     @Param("endTime") LocalDateTime endTime);

    @Select("select * from `order` where price_id = #{priceId}")
    List<Order> listByPriceId(Long priceId);
}
